package com.ynet.middleground.user.model;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ynet.middleground.user.bean.GetChannelReq;
import com.ynet.middleground.user.dao.SysDataDicMapper;
import com.ynet.middleground.user.dao.UserBaseInformationMapper;
import com.ynet.middleground.user.entity.SysDataDic;
import com.ynet.middleground.user.entity.UserBaseInformation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description: 内管系统管理模块
 * @author: DaiGaoLe
 * @create: 2019-12-04 1
 **/
@Component
public class TheInternalManagementModel extends ServiceImpl<UserBaseInformationMapper, UserBaseInformation> {


    @Autowired
    SysDataDicMapper sysDataDicMapper;

    public Map<String, String> getChannelInfo(GetChannelReq requestObject) {
        // 声明变量 begin
        String channeName = requestObject.getChanneName();
        String queryChanne = requestObject.getQueryChanne();
        Map<String, String> result = new HashMap<>();
        QueryWrapper<SysDataDic> queryWrapper = new QueryWrapper<>();
        // 声明变量 end

        queryWrapper.eq("data_type_no", "channel");
        queryWrapper.eq("data_type_name", "渠道");
        if (StringUtils.isNotEmpty(queryChanne)) {
            queryWrapper.like("data_no", queryChanne);
        }

        if (StringUtils.isNotEmpty(channeName)) {
            queryWrapper.like("data_name", channeName);
        }
        List<SysDataDic> sysDataDics = sysDataDicMapper.selectList(queryWrapper);
        sysDataDics.forEach(obj -> {
            result.put(obj.getDataNo(), obj.getDataName());
        });
        return result;
    }
}
